//
//  ZEmoticonCollectionView.swift
//  swift-weibo
//
//  Created by zero on 17/3/30.
//  Copyright © 2017年 zero. All rights reserved.
//

import UIKit

private let emoticonID = "emoticonID"

class ZEmoticonCollectionView: UICollectionView {

    
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        
        let layout = UICollectionViewFlowLayout()
        
        super.init(frame: frame, collectionViewLayout: layout)
        
        //  设置属性
        layout.itemSize = CGSize(width: ScreenWidth, height: 216 - 35)
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        layout.scrollDirection = .horizontal
        
        //  布局
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //  布局
    private func setupUI(){
        
        backgroundColor = UIColor.white
        
        //  代理
        dataSource = self
        
        //  注册
        register(ZEmoticonCollectionCell.self, forCellWithReuseIdentifier: emoticonID)
        
        //  设置属性
        self.bounces = false
        self.isPagingEnabled = true
        self.showsVerticalScrollIndicator = false
        self.showsHorizontalScrollIndicator = false
        
    }
}

extension ZEmoticonCollectionView:UICollectionViewDataSource{
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        
        return ZBundleTools.share.getThreeArray().count
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return ZBundleTools.share.getThreeArray()[section].count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: emoticonID, for: indexPath) as! ZEmoticonCollectionCell
        
//        indexPath.item
        cell.indexPath = indexPath
        
        cell.dataList = ZBundleTools.share.getThreeArray()[indexPath.section][indexPath.item]
        
        return cell
    }
    
}
